package controllers

import (
	"fmt"
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

//获取session
func GetSession(c *gin.Context) bool {
	session := sessions.Default(c)
	loginuser := session.Get("loginuser")
	//fmt.Println("loginuser:", loginuser)
	//
	//session.Delete("loginuser")
	//session.Save()
	//
	//
	//loginuserA := session.Get("loginuser")
	//fmt.Println("loginuser:", loginuserA)

	if loginuser != nil {
		return true
	} else {
		return false
	}
}


func SessionMiddleware() gin.HandlerFunc {

	// Do some initialization logic here

	// Foo()

	return func(c *gin.Context) {

		session := sessions.Default(c)
		loginuser := session.Get("loginuser")
		fmt.Println("loginuser:", loginuser)
		//fmt.Println("loginuser:", loginuser)
		//if loginuser != nil {
		//	//this.IsLogin = true
		//	//this.Loginuser = loginuser
		//
		//	c.Set("IsLogin", true)
		//	c.Set("Loginuser", loginuser)
		//
		//	//c.JSON(http.StatusOK, gin.H{"IsLogin": true, "Loginuser": loginuser})
		//} else {
		//	c.Set("IsLogin", false)
		//	//c.JSON(http.StatusOK, gin.H{"IsLogin": false})
		//	//this.IsLogin = false
		//}
		//islogin, _ := c.Get("IsLogin")
		//loginuser2, _ := c.Get("Loginuser")
		//fmt.Println("middleware...", islogin, loginuser2)
		//
		//c.Next()


	}

}